﻿CREATE FUNCTION [RestartFramework].[GetDistinctETLJobStageOrder]
(
	@pETLJobName SYSNAME
)
RETURNS TABLE AS RETURN
(
	SELECT	ejs.[ETLJobStageOrder]
	,		[ETLJobStageTally]				=	COUNT(*)
	,		[ETLJobStageOrderIsComplete]	=	CONVERT(BIT,MIN(CONVERT(TINYINT,ejs.[ETLJobStageIsComplete])))
	FROM	[RestartFramework].[ETLJob] ej
	INNER JOIN [RestartFramework].[ETLJobStage] ejs		ON	ej.[ETLJobId]	=	ejs.[ETLJobId]
	WHERE	ej.[ETLJobName] = @pETLJobName
	GROUP BY ejs.[ETLJobStageOrder]
)
